﻿// ********************************
// 2010.10.11
// MIB2实体辅助类
// Author:卢融凯
// ********************************
using System;
using System.Linq;
using System.Xml.Linq;

namespace SManage.Model.Trace
{
    internal static class Mib2SystemHelper
    {
        public static string GetFriendlyDeviceNameByObjectId(string sysObjectId)
        {
            if (String.IsNullOrEmpty(sysObjectId)){
                return String.Empty;
            }

            // TODO:Maybe remove .Descendants("Cisco") later.
            var routers = XDocument.Load("DeviceFriendlyNames.xml")
                                   .Descendants("Cisco")
                                   .Descendants("Router");
            var results = from router in routers
                          where router.Attribute("sysObjectId").Value == sysObjectId
                          select router.Value;
            return results.Count() > 0 ? results.First() : sysObjectId;
        }

        public static ServiceType GetDeviceSystemSupportServices(int? sysServices) {
            if (sysServices == null) {
                return ServiceType.None;
            }
            var result = (ServiceType)Enum.ToObject(typeof(ServiceType), sysServices);
            return result;
        }
    }
}
